<?php
function contains_invalid_chars($text){
	return preg_match("/[^a-zA-Z0-9äö]/", $text);
}

include_once("./db_functions.php");

$username = $_POST['user'];
$password = $_POST['passwd'];
if(contains_invalid_chars($username.$password) === 1)
{
	header("Location: ./index.php?p=info&invalidChars");
} else {
	$pass_length = strlen($password);
	$usrname_length = strlen($username);
	$min_length = 4;
	$max_length = 12;


	if( $pass_length >= $min_length && $pass_length <= $max_length && 
		$usrname_length >= $min_length && $usrname_length <= $max_length) 
	{
		$isAdditionSuccesfull = db_add_user($_POST['user'], $_POST['passwd'],$_POST['realname'], $_POST['organization']);
		if($isAdditionSuccesfull)
			header("Location: index.php?p=info&registersuccess");
		else
			header("Location: index.php?p=info&registerfail");
	} else {
		header("Location: ./index.php?p=info&giveinfo");
	}
}
?>


